/**
 * 获取输入时间距今时间
 * @param {String} ('2021-5-5 12:00:00')
 * @returns String
 */
function dateFormat(time){
    
    let nowTime = new Date()
    let nowTimes = nowTime.getTime()
    let oldTime = new Date(time)
    let oldTimes =oldTime.getTime()
    let diff = (nowTimes - oldTimes )/1000

    if(diff < 10) return '刚刚'
    if(diff < 60) return `${diff}秒前`
    if(diff < 60*60) return `${Math.floor(diff / 60)}分钟前`
    if(diff < 60*60*60) return `${Math.floor(diff / 60/60)}小时前`
    if(diff < 60*60*60*24) return `${Math.floor(diff / 60/60/24)}天前`
    if(diff < 60*60*60*24*30) return `${Math.floor(diff / 60/60/24/30)}月前`
    if(diff < 60*60*60*24*30*12) return `${Math.floor(diff / 60/60/24/30/12)}年前`

}



 /**
  * 格式化时间：返回年月日时分秒格式
  * @param {string} str 
  * @returns String
  */
function format(str){
    var d=new Date()
    console.log(d)
    str=str.replaceAll('Y',d.getFullYear())
    str=str.replaceAll('m',d.getMonth()+1)
    str=str.replaceAll('d',d.getDate())
    str=str.replaceAll('H',d.getHours())
    str=str.replaceAll('i',d.getMinutes())
    str=str.replaceAll('s',d.getSeconds())
    return str
}



/**
 * 判断浏览器类型
 * @param {} 
 * @returns string
*/
function browser(){

    if(navigator.userAgent.indexOf('Firebox')!== -1){
     return '火狐浏览器'
    } else if(navigator.userAgent.indexOf('Chrome')!== -1){
    return '谷歌浏览器'
    } else if(navigator.userAgent.indexOf('Safari')!== -1){
        return '苹果浏览器'
    } else if(navigator.userAgent.indexOf('Opera')!== -1){
        return 'Opera浏览器'
    } else if(navigator.userAgent.indexOf('Trident')!== -1){
        return 'IE浏览器'
    }
      
} 

/**
 * 判断是PC还是移动端
 * @param {} 
 * @returns {str}
*/
function PcandYd() {
    data = navigator.userAgent
    if ((data.indexOf('Mac')||data.indexOf('Windows')||data.indexOf('Linux'))||data.indexOf('win') !== -1){
        return '电脑端'
    } 
    if ((data.indexOf('iPhone')||data.indexOf('iPad')||data.indexOf('Android')||data.indexOf('Mobile')) !== -1){
        return '移动端'
    } 
}


/**
 * 判断是否是微信内置浏览器
 * @param {} 
 * @returns {str}
*/
function weixin(){
    var ua = navigator.userAgent.toLowerCase();
 if(ua.match(/MicroMessenger/i)=="micromessenger") {
         return true;
     } else {
        return false;
     }
 }




/**
  * 判断标签样式
  * @param object string 举例('divObj',)
  * @return string
  */

 function getStyle(tagObj,cssAttr){
    if(window.getComputedStyle){
        return getComputedStyle(tagObj)[cssAttr] //对象的键taObj是变量
    } else{
        return tagObj.currentStyle[cssAttr]
    }

}
